package com.example.springaopdemo.demos.web.proxy;


import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;
public class CGLIBInterceptor implements MethodInterceptor {
    private Object target;

    public CGLIBInterceptor(Object target) {
        this.target = target;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects,
                            MethodProxy methodProxy) throws Throwable {
        // 代理增强内容
        System.out.println("我是中介, 开始代理");
        //通过反射调⽤被代理类的⽅法
        Object retVal = methodProxy.invoke(target, objects);
        //代理增强内容
        System.out.println("我是中介, 代理结束");
        return retVal;
    }
}
